#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    string s;
    getline(cin, s);
    sscanf(s.c_str(), "%d", &n);
    while (n--) {
        string str; 
        getline(cin, str);
        stringstream sin(str);
        vector<string> vec;
        vector<string> res;
        while (sin >> s) vec.push_back(s);
        stack<char> stk;
        for (auto& v : vec) {
            for (int i = 0; i < v.size(); i++) {
                stk.push(v[i]);
            }
            string ans = "";
            while (!stk.empty()) {
                char ch = stk.top();
                ans += ch;
                stk.pop();
            }   
            res.push_back(ans);
        }
        for (int i = 0; i < res.size(); i++) {
            if (i < res.size() - 1) cout << res[i] << " ";
            else cout << res[i] << endl;
        }
    }
    return 0;
}